﻿Partial Public Class Wfrm_Consultar_OC_SOL
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            ViewState("usu") = Session("usuario")
            Cargar_clinica()
        End If

    End Sub

    Protected Sub btnBuscaSol_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnBuscaSol.Click
        Carga_Grilla_OC()
    End Sub
    Sub Cargar_clinica()
        'cmb_clinica
        Dim exec As New DotNetDal.SQLPersistence(False, "cnn", DotNetDal.SQLPersistence.Provider.SQLCLIENT)
        Dim rp As New DotNetResponse.SQLPersistence
        rp.StoredProcedure = "SP_OC_GET_CLINICAS"       
        exec.ExecuteDataTable(rp)
        cmb_clinica.DataValueField = "ncodigo_pki"
        cmb_clinica.DataTextField = "tNombreFantasia"
        cmb_clinica.DataSource = rp.DtTable
        cmb_clinica.UpdateAfterCallBack = True


    End Sub
    Sub Carga_Grilla_OC()
        Try


            Dim exec As New DotNetDal.SQLPersistence(False, "cnn", DotNetDal.SQLPersistence.Provider.SQLCLIENT)
            Dim rp As New DotNetResponse.SQLPersistence
            rp.StoredProcedure = "SP_OC_GET_ORDEN_COMPRA_SOL"
            rp.AddParametro(Val(txtNsolicitud.Text))
            If txtStartDate.Text.Trim.Length > 0 Then
                rp.AddParametro(Convert.ToDateTime(txtStartDate.Text).ToString("yyyyMMdd"))
            Else
                rp.AddParametro("0")
            End If
            If txtEndDate.Text.Trim.Length > 0 Then
                rp.AddParametro(Convert.ToDateTime(txtEndDate.Text).ToString("yyyyMMdd"))
            Else
                rp.AddParametro("0")
            End If

            rp.AddParametro(cmb_estado_solicitud.SelectedValue)
            rp.AddParametro(ViewState("usu"))


            If txt_Sol.Text.Trim = "" Then
                rp.AddParametro(Nothing)
            Else
                rp.AddParametro(txt_Sol.Text.Trim)
            End If

            If cmb_clinica.SelectedValue = "-1" Then
                rp.AddParametro(Nothing)
            Else
                rp.AddParametro(cmb_clinica.SelectedValue)
            End If

            exec.ExecuteDataTable(rp)
            Grilla_OC_enc.DataSource = rp.DtTable
            Grilla_OC_enc.Visible = True
            Panel1.Visible = True
            Panel1.UpdateAfterCallBack = True
            Grilla_OC_enc.DataBind()
            Grilla_OC_enc.UpdateAfterCallBack = True

        Catch ex As Exception


        End Try

    End Sub

    Protected Sub lnk_despachar_Click(ByVal sender As Object, ByVal e As EventArgs)
        lbl_nro_oc.Text = DirectCast(sender.parent.parent, DataGridItem).Cells(2).Text
        lbl_nro_oc.UpdateAfterCallBack = True

        lbl_fecha.Text = DirectCast(sender.parent.parent, DataGridItem).Cells(4).Text
        lbl_fecha.UpdateAfterCallBack = True

        lbl_proveedor.Text = DirectCast(sender.parent.parent, DataGridItem).Cells(3).Text
        lbl_proveedor.UpdateAfterCallBack = True

        Carga_Productos(DirectCast(sender.parent.parent, DataGridItem).Cells(2).Text)

        Panel1.Visible = True
        lblSolicitud7.Visible = True
        lblSolicitud6.Visible = True
        lbl_proveedor.Visible = True
        lbl_nro_oc.Visible = True
        'lblSolicitud2.Visible = True
        lblSolicitud1.Visible = True

        Panel1.UpdateAfterCallBack = True
        lblSolicitud7.UpdateAfterCallBack = True
        lblSolicitud6.UpdateAfterCallBack = True
        lbl_proveedor.UpdateAfterCallBack = True
        lbl_nro_oc.UpdateAfterCallBack = True
        'lblSolicitud2.UpdateAfterCallBack = True
        lblSolicitud1.UpdateAfterCallBack = True

    End Sub
    Sub Carga_Productos(ByVal id_oc As String)
        Dim exec As New DotNetDal.SQLPersistence(False, "cnn", DotNetDal.SQLPersistence.Provider.SQLCLIENT)
        Dim rp As New DotNetResponse.SQLPersistence
        rp.StoredProcedure = "SP_GET_PRODUCTOS_ORDEN_COMPRA_SOL"
        rp.AddParametro(id_oc)
        rp.AddParametro(ViewState("usu"))
        exec.ExecuteDataTable(rp)

        If Not rp.TieneDatos Then
            If Anthem.Manager.IsCallBack Then
                Anthem.Manager.AddScriptForClientSideEval("alert('" & "No existen productos en la Orden de Compra" & "')")
            Else
                Page.ClientScript.RegisterStartupScript(Me.GetType, "alertar", "<script>alert('" & "No existen productos en la Orden de Compra" & "')</script>")
            End If
        End If

        DataGrid4.DataSource = rp.DtTable
        DataGrid4.DataBind()
        DataGrid4.UpdateAfterCallBack = True
    End Sub


End Class